package com.abcdefg.service;

import com.abcdefg.api.ProduceApi;
import com.abcdefg.mapper.OrderMapper;
import com.abcdefg.model.OrderInfo;
import com.abcdefg.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProduceApi produceapi;

    public OrderInfo selectOrderById(int orderId) {
        OrderInfo orderInfo = orderMapper.selectOrderById(orderId);
//        System.out.println(orderInfo.toString());
//        String url="http://produce-service/product/"+orderInfo.getProductId();
//        ProductInfo forObject = restTemplate.getForObject(url, ProductInfo.class);
        System.out.println(orderInfo.toString());
        ProductInfo productById = produceapi.getProductById(orderInfo.getProductId());
        orderInfo.setProductInfo(productById);
        return orderInfo;
    }
}
